#pragma once
/***************************************** 
 *
 * Listing 1.2
 *
 * Example performing I/O on s socket pair:
 * 
 * ******************************************/ 
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/shm.h>

// for socketpair sendmsg/recvmsg
typedef struct {
     unsigned int  command;
     pid_t   pid;
     int   slot;
     FILE  *fd;
} http_channel_t;

// all son process infomation , 
typedef struct {
    pid_t           pid;   // process id
    int                 status;  // process status
    int        channel[2];  // process send|recv msg id

    //HTTP_spawn_proc_pt   proc;
    void               *data;
    char               *name;

    unsigned            respawn:1;
    unsigned            just_spawn:1;
    unsigned            detached:1;
    unsigned            exiting:1;
    unsigned            exited:1;
} http_process_t;

#define HTTP_MAX_PROCESSES  100

#define HTTP_CMD_OPEN_CHANNEL   1
#define HTTP_CMD_CLOSE_CHANNEL  2
#define HTTP_CMD_QUIT           3
#define HTTP_CMD_TERMINATE      4
#define HTTP_CMD_REOPEN         5

extern http_process_t   http_processes[HTTP_MAX_PROCESSES];
extern int http_last_process;

int work_process_cycle();
